"""
自动读取日志文件，模拟日志的输出
"""
import time

log = open('log.txt', 'a+')
log.seek(0)
line_num = len(log.readlines())
try:
    while True:
        time.sleep(2)
        line_num = line_num + 1
        log.write('%d. %s\n' % (line_num, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())))
        log.flush()
except KeyboardInterrupt:
    print('程序结束')
    log.close()
